package com.sales.dao;

import com.sales.entity.CommissionDetails;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import javax.validation.constraints.Max;
import java.util.List;

/**
 * Created by lihu on 2017/10/14.
 */
public interface CommissionDetailsDao extends PagingAndSortingRepository<CommissionDetails, String> {

    /**
     * 查询对应店铺提成记录
     *
     * @param username
     * @param storeId
     * @return
     */
    CommissionDetails findByUsernameAndStoreId(String username, String storeId);

    /**
     * 获取用户对应店铺提成金额
     *
     * @param username
     * @param storeId
     * @return
     */
    @Query(value = "select store_id storeId,sum(commission) commission" +
            " from commission_details where username=?1 " +
            " and store_id in ?2 GROUP BY store_id", nativeQuery = true)
    List<Object[]> getCommissionAll(String username, List<String> storeId);
}
